home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / libg_261.zip / libg_261 / libg++ / etc / trie-gen / options.h < prev    next >
C/C++ Source or Header  |  1994-05-13  |  3KB  |  94 lines

  1. /* This may look like C code, but it is really -*- C++ -*- */
  2.  
  3. /* Handles parsing the Options provided to the user.
  4.  
  5.    Copyright (C) 1989 Free Software Foundation, Inc.
  6.    written by Douglas C. Schmidt (schmidt@ics.uci.edu)
  7.  
  8. This file is part of GNU TRIE-GEN.
  9.  
  10. GNU TRIE-GEN is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 1, or (at your option)
  13. any later version.
  14.  
  15. GNU TRIE-GEN is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. GNU General Public License for more details.
  19.  
  20. You should have received a copy of the GNU General Public License
  21. along with GNU TRIE-GEN; see the file COPYING.  If not, write to
  22. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  23.  
  24. /* This module provides a uniform interface to the various options available
  25.    to a user of the minimal-prefix trie generator.
  26.    The overall design of this module was an experiment in using C++
  27.    classes as a mechanism to enhance centralization of option and
  28.    and error handling, which tend to get out of hand in a C program. */
  29.  
  30. #ifndef options_h
  31. #define options_h 1
  32.  
  33. /* Enumerate the potential debugging Options. */
  34.  
  35. enum Option_Type
  36. {
  37.   DEBUG        = 01,  /* Enable debugging option. */
  38.   COMPACT      = 02,  /* Compact the output tables. */
  39.   FULL         = 04,  /* Generate a full table. */
  40.   CONST        = 010  /* Make the generated tables readonly (const). */
  41. };
  42.  
  43. /* Class manager for program options. */
  44.  
  45. class Options 
  46. {
  47. public:
  48.                       Options (void);
  49.                      ~Options (void);
  50.   const char         *program_name (void);
  51.   int                 operator[] (Option_Type option);
  52.   void                operator() (int argc, char *argv[]);
  53.   void                operator= (enum Option_Type);
  54.   void                operator!= (enum Option_Type);
  55.   static void         print_options (void);
  56.  
  57. private:
  58.   static int          option_word;                        /* Holds the user-specified Options. */
  59.   static int          argument_count;
  60.   static char       **argument_vector;
  61.   static void         usage (void);                       /* Prints proper program usage. */
  62. };
  63.  
  64. /* Global option coordinator for the entire program. */
  65. extern Options option;       
  66.  
  67. #ifdef __OPTIMIZE__
  68. inline const char *
  69. Options::program_name (void)
  70. {
  71.   return argument_vector[0];
  72. }
  73.  
  74. inline int  
  75. Options::operator[] (Option_Type option) /* True if option enable, else false. */
  76.   return option_word & option;
  77. }
  78.  
  79. inline void
  80. Options::operator = (enum Option_Type opt) /* Enables option OPT. */
  81. {
  82.         option_word |= opt;
  83. }
  84.  
  85. inline void
  86. Options::operator != (enum Option_Type opt) /* Disables option OPT. */
  87. {
  88.         option_word &= ~opt;
  89. }
  90.  
  91. #endif
  92. #endif
  93.